#include "creature.h"
#include "monde.h"
#include "FenPrincipale.h"
#include "widgetparams.h"

#include <QtCore/QDebug>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QMdiArea>
#include <QtGui/QMenuBar>

FenPrincipale::FenPrincipale() {
    m_widgetCentral = new QMdiArea(this);
    setCentralWidget(m_widgetCentral);

    m_widgetParams = new WidgetParams();
    addDockWidget(Qt::LeftDockWidgetArea, m_widgetParams);
    m_widgetParams->show();

    creerActions();
    creerMenus();
}

FenPrincipale::~FenPrincipale() {
}

void FenPrincipale::creerActions() {
    m_actionLancerSimu = new QAction(trUtf8("&Lancer la simulation"), this);
    m_actionLancerSimu->setShortcut(trUtf8("F5"));

    m_actionQuitter = new QAction(trUtf8("&Quitter"), this);
    m_actionQuitter->setShortcut(trUtf8("Ctrl+Q"));

    QObject::connect(m_actionLancerSimu, SIGNAL(triggered()), this, SLOT(lancerSimu()));
    QObject::connect(m_actionQuitter, SIGNAL(triggered()), this, SLOT(quitter()));
}

void FenPrincipale::creerMenus() {
    QMenu* menuFichier = menuBar()->addMenu(tr("&Fichier"));
    menuFichier->addAction(m_actionLancerSimu);
    menuFichier->addSeparator();
    menuFichier->addAction(m_actionQuitter);
}

void FenPrincipale::lancerSimu() {
    // Incrémentation de durée de vie par mutations, nombre de tours
    m_monde = new Monde(m_widgetParams->nbIncParMut(), m_widgetParams->nbTours());
    m_monde->ajouterCreature(5);
    m_monde->ajouterCreature(7);
    Creature* c = new Creature(m_monde->m_listeCreatures.at(0), m_monde->m_listeCreatures.at(1));
    m_monde->m_listeCreatures.append(c);
    qDebug() << "Taille avant la boucle : " << m_monde->m_listeCreatures.size();
    for (int i = 0; i < m_monde->m_nbTours; i++)
        m_monde->tour();
    qDebug() << "Taille après la boucle : " << m_monde->m_listeCreatures.size();
}

void FenPrincipale::quitter() {
    qApp->quit();
}
